package com.panshi.service.impl;

import com.panshi.dao.ITypeDao;
import com.panshi.service.ITypeService;
import com.panshi.vo.search.TypeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class TypeServiceImpl implements ITypeService {
    @Autowired
    private ITypeDao typeDao;
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @Override
    public List<TypeVo> queryType() {
        List<TypeVo> list = null;
        if (redisTemplate.hasKey("hasbei:type:zx")){
            list = (List<TypeVo>) redisTemplate.opsForValue().get("hasbei:type:zx");
        }else {
            list = typeDao.queryType();
            redisTemplate.opsForValue().set("hasbei:type:zx", list);
        }
        return list;
    }
}
